home *** CD-ROM | disk | FTP | other *** search
- Path: watnews.watson.ibm.com!usenet
- From: "John D. Prokopek" <jprok@watson.ibm.com>
- Newsgroups: comp.os.ms-windows.programmer.ole,comp.lang.c++
- Subject: Re: Problems VC++4.0 & StringFromCLSID function
- Date: Sat, 20 Jan 1996 09:54:23 -0800
- Organization: IBM T.J. Watson Research Center
- Message-ID: <31012C4F.10CC@watson.ibm.com>
- References: <4djn2d$mps@earth.superlink.net>
- NNTP-Posting-Host: internet-gw.watson.ibm.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0b3 (Win95; I)
-
- Ananda Subramaniam wrote:
- >
- > Hi,
- >
- > I have an OLE sample that I wrote and compiled in VC++ 2.0 without any problems.
- > However, when I tried to compile in VC++ 4.0, I had trouble with the
- > StringFromCLSID function.
- >
- > I get a message "cannot convert 2nd parameter char ** to unsigned short**"
- >
- > The Prototype for StringFromCLSID is:
- > StringFromCLSID(REFCLSID, LPOLESTR *);
- >
- > I am passing as my second parameter a LPSTR *, which shouldn't be a problem
- > because grepping through the several include files provided by MS there is a
- > typedef as follows
- >
- > typedef LPSTR LPOLESTR;
- >
- > The compiler seems to think that LPOLESTR is of type unsigned short.
- > To further confirm this, I changed the type of my string to LPOLESTR and the
- > compiler went past StringFromCLSID function but complained on the next line
- > where I had AfxMessageBox(mystr). The compiler said "non of the 2 overloads can
- > covert parameter one from type unsigned short * "
- >
- > After this, I went and modified the header file that has the prototype for
- > StringFromCLSID (objbase.h) and modified the prototype from LPOLESTR to LPSTR
- > and the app compiled and sort of worked.
- >
- > I am running out of ideas, plus it does not help being the only C++ programmer
- > in the office. Any help will be appreciated.
- >
- > Ananda
- > email: ananda@mars.superlink.net
-
- This little problem bugged me too.
- There is an easy way to convert-
- If you include afxpriv.h there are conversion macros that will allocate
- memory perform the necessary conversion and return the proper pointer.
-
- here is a little sample from my junk...
-
- #include "afxpriv.h"
-
- void CBaseObjectApp::RegisterServer(void)
- {
- OLECHAR szID[128];
- TCHAR szCLSID[128];
- TCHAR szModule[512];
- USES_CONVERSION; << this initializes some vars
-
- StringFromGUID2(CLSID_ChatSrv, (LPOLESTR)szID, 128); << LPOLESTR is
- what is expected
- lstrcpy(szCLSID, TEXT("CLSID\\"));
- lstrcat(szCLSID, OLE2CT(szID)); << OLE2CT performs a conversion
- << and returns the correct
- << pointer
- << check it out
- I still need to compile with MBCS and have had no luck compileing with
- _UNICODE defined but that is another headache.
- Microsoft - "Do it our way until we tell you otherwise"
-
- later
- johnp
-